<template>
  <div class="home">
    <el-container>
      <!-- 左侧菜单栏 -->
      <el-aside width="auto">
        <!-- 获取左侧授权菜单与路由授权按钮 -->
        <MenuList @btns="getBtns"></MenuList>
      </el-aside>
      <!-- 容器 -->
      <el-container>
        <!-- 头部 -->
        <el-header class="haed-nav" height="50px">
          <!-- 获取登录用户信息 -->
          <HeadNav></HeadNav>
        </el-header>
        <!-- 主要内容 -->
        <el-main class="main">
          <!-- 路由出口 -->
          <!-- 拦截验证 父组件通信子组件：按钮级权限 -->
          <router-view v-if="isRouterAlive" :btns="btns"></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
// 引入左侧菜单组件
import MenuList from '@/components/MenuList/index.vue';
// 引入顶部菜单组件
import HeadNav from '@/components/HeadNav/index.vue';

export default {
  name: 'home',
  data () {
    return {
      // 按钮级权限
      btns: {},
      // keep-alive状态开关
      isRouterAlive: true
    };
  },
  provide () {
    // 无白屏刷新注册
    return {
      reload: this.reload
    };
  },
  // 注册组件
  components: {
    MenuList,
    HeadNav
  },
  methods: {
    // 获取按钮级权限
    getBtns (data) {
      this.btns = data;
    },
    // 局部刷新
    reload () {
      this.isRouterAlive = false;
      this.$nextTick(function () {
        this.isRouterAlive = true;
      });
    }
  }
};
</script>

<style lang='scss' scoped>
@import './index.scss';
</style>
